home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glypha 3.02 / source / Code ƒ / J-Glypha.p < prev   
Encoding:
Text File  |  1993-06-03  |  10.8 KB  |  374 lines  |  [TEXT/PJMM]

  1. program Glypha;    {Glypha 3.01 ©1990, 1991, 1992 , 1993 Soft Dorothy}
  2.  
  3.     uses
  4.         AboutWndo, Dialogs, Sound, GameUtils, Enemies, GlyphaGuts, MainWndo, Initialize, Menus;
  5.  
  6.     const
  7.         kSpaceKey = $31;
  8.         kLeftKey1 = $29;
  9.         kLeftKey2 = $00;
  10.         kRightKey1 = $27;
  11.         kRightKey2 = $01;
  12.  
  13.     var
  14.         myEvent: EventRecord;
  15.         code, index, theMenu, theItem, chCode, flashes: integer;
  16.         ch: char;
  17.         dummyLong, mResult: LongInt;
  18.         whichWindow: WindowPtr;
  19.         tempRect: Rect;
  20.         theInput: TEHandle;
  21.         mousePt: Point;
  22.         err: OSErr;
  23.  
  24. {===================================}
  25.  
  26.     procedure CheckOurEnvirons;
  27.         var
  28.             err: OSErr;
  29.             thisWorld: SysEnvRec;
  30.     begin
  31.         rightOffset := (ScreenBits.bounds.right - 512) div 2;
  32.         downOffset := (ScreenBits.bounds.bottom - 342) div 2;
  33.  
  34.         err := SysEnvirons(1, thisWorld);    {Check set up the Mac game is on    }
  35.         with thisWorld do
  36.             begin
  37.                 if (machineType < 1) then        {If less than a Mac 512KE (<1)        }
  38.                     ExitToShell                                    {quit to the Finder now!                    }
  39.                 else
  40.                     begin
  41.                         if (machineType < 3) then
  42.                             onFastMachine := FALSE
  43.                         else
  44.                             onFastMachine := TRUE;
  45.                         if (systemVersion < $0602) then
  46.                             inhibitSound := TRUE        {Global to prevent sound on older    }
  47.                         else                                            {versions of the System.                    }
  48.                             inhibitSound := FALSE;    {Or, we allow sound.                            }
  49.                     end;
  50.             end;
  51.     end;
  52.  
  53. {===================================}
  54.  
  55.     procedure CheckTheMouse;
  56.         var
  57.             screenPos: Integer;
  58.     begin
  59.         GetMouse(mousePt);
  60.         screenPos := (mousePt.h - 256 - rightOffset) div 8;
  61.         if (screenPos > 16) then
  62.             screenPos := 16;
  63.  
  64.         with thePlayer do
  65.             begin
  66.                 if (facing = 0) then
  67.                     begin
  68.                         if (screenPos < 0) then
  69.                             facing := 1
  70.                         else
  71.                             begin
  72.                                 if (screenPos > horiVel) then
  73.                                     keyStillDown := TRUE
  74.                                 else
  75.                                     keyStillDown := FALSE;
  76.                             end;
  77.                     end
  78.                 else
  79.                     begin
  80.                         if (screenPos > 0) then
  81.                             facing := 0
  82.                         else
  83.                             begin
  84.                                 if (screenPos < horiVel) then
  85.                                     keyStillDown := TRUE
  86.                                 else
  87.                                     keyStillDown := FALSE;
  88.                             end;
  89.                     end;
  90.             end;
  91.     end;
  92.  
  93. {===================================}
  94.  
  95.     procedure CheckTheKeyboard;
  96.         var
  97.             keyState: KeyMap;
  98.  
  99.     begin
  100.         keyStillDown := FALSE;
  101.         GetKeys(keyState);
  102.         if ((keyState[kLeftKey1]) or (keyState[kLeftKey2])) then
  103.             keyStillDown := TRUE
  104.         else
  105.             begin
  106.                 if ((keyState[kRightKey1]) or (keyState[kRightKey2])) then
  107.                     keyStillDown := TRUE;
  108.             end;
  109.     end;
  110.  
  111. {===================================}
  112.  
  113.     procedure HandleGameEvent (myEvent: EventRecord);
  114.         var
  115.             wasPort: GrafPtr;
  116.     begin
  117.         case myEvent.what of
  118.             KeyDown: 
  119.                 begin
  120.                     chCode := BitAnd(myEvent.message, CharCodeMask);
  121.                     ch := CHR(chCode);
  122.                     if (ODD(myEvent.modifiers div CmdKey)) then
  123.                         begin
  124.                             if (ch = 'p') or (ch = 'P') then
  125.                                 DoPause;
  126.                             if (ch = 'e') or (ch = 'E') then
  127.                                 DoEnd;
  128.                             if (ch = 'q') or (ch = 'Q') then
  129.                                 DoEnd;
  130.                         end
  131.                     else if (keyboardControl) then
  132.                         with thePlayer do
  133.                             case chCode of
  134.                                 32:        {flap}
  135.                                     begin
  136.                                         state := TRUE;
  137.                                     end;
  138.                                 34, 39, 83, 115:    {point right}
  139.                                     begin
  140.                                         facing := 0;
  141.                                     end;
  142.                                 58, 59, 65, 97:        {point left}
  143.                                     begin
  144.                                         facing := 1;
  145.                                     end;
  146.                                 82, 114:                    {refresh}
  147.                                     begin
  148.                                         Update_MainWndo(mainWndo);
  149.                                         DrawMenuBar;
  150.                                         FlashMenuBar(0);
  151.                                     end;
  152.                                 70, 102:                    {flush}
  153.                                     begin
  154.                                         GetPort(wasPort);
  155.                                         SetPort(mainWndo);
  156.                                         FillRect(mainWndo^.portBits.bounds, black);
  157.                                         SetPort(wasPort);
  158.                                     end;
  159.  
  160.                                 otherwise
  161.                                     begin
  162.                                     end;
  163.                             end;    {end case chCode of}
  164.                 end;        {end of KeyDown event}
  165.             MouseDown: 
  166.                 begin
  167.                     thePlayer.state := TRUE;
  168.                 end;
  169.             UpDateEvt:                {Update event for a window}
  170.                 begin                        {Handle the update}
  171.                     whichWindow := WindowPtr(myEvent.message); {Get the window the update is for}
  172.                     BeginUpdate(whichWindow);     {Set the clipping to the update area}
  173.                     Update_MainWndo(whichWindow);
  174.                     EndUpdate(whichWindow);       {Return to normal clipping area}
  175.                     DrawMenuBar;
  176.                     FlashMenuBar(0);
  177.                 end;
  178.             otherwise
  179.                 begin
  180.                 end;
  181.         end;
  182.     end;
  183.  
  184. {===================================}
  185.  
  186. begin
  187.     MaxApplZone;
  188.     MoreMasters;                   {This reserves space for more handles}
  189.     MoreMasters;
  190.     MoreMasters;
  191.     MoreMasters;
  192.     CheckOurEnvirons;
  193.     FlushEvents(everyEvent, 0);    {Clear out all events}
  194.     Init_LogoWindo;
  195.     Open_LogoWindo(rightOffset, downOffset);
  196.     SetCursor(GetCursor(watchCursor)^^);
  197.     Init_My_Menus;                            {Initialize menu bar}
  198.     FlashMenuBar(0);
  199.     doneFlag := FALSE;
  200.     theInput := nil;
  201.     InitVariables;
  202.     NewLightning;
  203.     ReadInScores;
  204.     Init_MainWndo;                            {Set mainWndo's pointer to nil}
  205.     Open_MainWndo(rightOffset, downOffset);    {Open the window}
  206.     RedoTheBackground;
  207.     Close_LogoWindo;
  208.     DoTheSound('music.snd', TRUE);
  209.     ReDrawHiScores;
  210.     InitCursor;
  211.     FlushEvents(everyEvent, 0);
  212.     Delay(160, dummyLong);
  213.     CopyMask(offPlayerMap, offPlayerMap, mainWndo^.portBits, eyeRects[4], eyeRects[4 + 5], theEye.dest);
  214.     DoTheSound('lightning.snd', TRUE);
  215.     SetPort(mainWndo);
  216.     for index := 1 to 3 do
  217.         StrikeLightning(upperEye);
  218.     CopyBits(offVirginMap, mainWndo^.portBits, theEye.dest, theEye.dest, srcCopy, playRgn);
  219.     FlushEvents(everyEvent, 0);
  220.  
  221.     repeat
  222.         if (theInput <> nil) then
  223.             TEIdle(theInput);
  224.         SystemTask;
  225.  
  226.         CopyBits(offVirginMap, offLoadMap, flameRect[0], flameRect[0], srcCopy, nil);
  227.         CopyBits(offVirginMap, offVirginMap, flameRect[1], flameRect[0], srcCopy, nil);
  228.         CopyBits(offLoadMap, offVirginMap, flameRect[0], flameRect[1], srcCopy, nil);
  229.         CopyBits(offVirginMap, mainWndo^.portBits, flameRect[0], flameRect[0], srcCopy, nil);
  230.         CopyBits(offVirginMap, mainWndo^.portBits, flameRect[1], flameRect[1], srcCopy, nil);
  231.         Delay(4, dummyLong);
  232.         if DoRandom(200) = 0 then
  233.             begin
  234.                 SetPort(mainWndo);
  235.                 flashes := DoRandom(4) + 1;
  236.                 CopyMask(offPlayerMap, offPlayerMap, mainWndo^.portBits, eyeRects[4], eyeRects[4 + 5], theEye.dest);
  237.                 DoTheSound('lightning.snd', TRUE);
  238.                 for index := 1 to flashes do
  239.                     StrikeLightning(upperEye);
  240.                 CopyBits(offVirginMap, mainWndo^.portBits, theEye.dest, theEye.dest, srcCopy, playRgn);
  241.             end;
  242.  
  243.         if GetNextEvent(everyEvent, myEvent) then
  244.             begin
  245.                 code := FindWindow(myEvent.where, whichWindow); {Get which window the event happened in}
  246.                 case myEvent.what of                        {Decide type of event                    }
  247.                     MouseDown:                                    {Mouse button pressed                    }
  248.                         begin                                        {Handle the pressed button                }
  249.                             if (code = inMenuBar) then            {See if a menu selection                }
  250.                                 begin                                    {Get the menu selection and handle it    }
  251.                                     mResult := MenuSelect(myEvent.Where);                {Do menu selection    }
  252.                                     theMenu := HiWord(mResult);            {Get the menu list number            }
  253.                                     theItem := LoWord(mResult);            {Get the menu list item number    }
  254.                                     Handle_My_Menu(theMenu, theItem, theInput);         {Handle the menu    }
  255.                                 end;                                            {End of inMenuBar                    }
  256.                             if (code = inSysWindow) then                {See if a DA selection        }
  257.                                 SystemClick(myEvent, whichWindow); {Let other programs in        }
  258.                         end;                                                {End of MouseDown            }
  259.                     KeyDown:                                            {Handle key inputs            }
  260.                         begin
  261.                             with myevent do
  262.                                 begin
  263.                                     chCode := BitAnd(message, CharCodeMask);    {Get character}
  264.                                     ch := CHR(chCode);                    {Change to ASCII}
  265.                                     if (Odd(modifiers div CmdKey)) then        {See if Command key is down}
  266.                                         begin
  267.                                             mResult := MenuKey(ch);           {See if menu selection}
  268.                                             theMenu := HiWord(mResult); {Get the menu list number}
  269.                                             theItem := LoWord(mResult); {Get the menu item number}
  270.                                             if (theMenu <> 0) then        {See if a list was selected}
  271.                                                 Handle_My_Menu(theMenu, theItem, theInput); {Do the menu selection}
  272.                                         end
  273.                                     else
  274.                                         case ch of
  275.                                             'l': 
  276.                                                 begin
  277.                                                     SetPort(mainWndo);
  278.                                                     for index := 1 to 10 do
  279.                                                         StrikeLightning(DoRandom(4));
  280.                                                 end;
  281.                                             'L': 
  282.                                                 begin
  283.                                                     SetPort(mainWndo);
  284.                                                     flashes := DoRandom(4) + 1;
  285.                                                     CopyMask(offPlayerMap, offPlayerMap, mainWndo^.portBits, eyeRects[4], eyeRects[4 + 5], theEye.dest);
  286.                                                     DoTheSound('lightning.snd', TRUE);
  287.                                                     for index := 1 to flashes do
  288.                                                         StrikeLightning(upperEye);
  289.                                                     CopyBits(offVirginMap, mainWndo^.portBits, theEye.dest, theEye.dest, srcCopy, playRgn);
  290.                                                 end;
  291.                                             'm', 'M': 
  292.                                                 DoTheSound('music.snd', TRUE);
  293.                                             otherwise
  294.                                                 begin
  295.                                                 end;
  296.                                         end;
  297.                                 end;                {End for with}
  298.                         end;                        {End for KeyDown,AutoKey}
  299.                     UpDateEvt:                {Update event for a window}
  300.                         begin                        {Handle the update}
  301.                             whichWindow := WindowPtr(myEvent.message); {Get the window the update is for}
  302.                             BeginUpdate(whichWindow);     {Set the clipping to the update area}
  303.                             Update_MainWndo(whichWindow);
  304.                             EndUpdate(whichWindow);       {Return to normal clipping area}
  305.                             DrawMenuBar;
  306.                             FlashMenuBar(0);
  307.                         end;                            {End of UpDateEvt}
  308.                     ActivateEvt:                   {Window activated event}
  309.                         begin                           {Handle the activation}
  310.                             whichWindow := WindowPtr(myevent.message); {Get the window to be activated}
  311.                             if odd(myEvent.modifiers) then {Make sure it is Activate and not DeActivate}
  312.                                 SelectWindow(whichWindow);    {Activate the window by selecting it}
  313.                         end;                            {End of ActivateEvt}
  314.                     otherwise
  315.                         begin
  316.                         end;
  317.                 end;                              {End of case}
  318.  
  319.                 while (playing) do
  320.                     begin
  321.                         gameCycle := gameCycle + 1;
  322.                         if keyboardControl then
  323.                             CheckTheKeyboard
  324.                         else
  325.                             CheckTheMouse;
  326.                         if (stonesSliding) then
  327.                             SlideTheStones;
  328.                         MoveThePlayer;
  329.                         HandleTheEnemies;
  330.                         UpdateEye;
  331.                         with thePlayer do
  332.                             begin
  333.                                 if ((dest.bottom > 281) and (dest.left > 347) and (not otherState)) then
  334.                                     UpdateTheHand
  335.                                 else if (theHand.state) then
  336.                                     RetractTheHand;
  337.                                 DrawBeasts;
  338.                                 DrawPlayer(dest, oldDest);
  339.                                 oldDest := dest;
  340.                             end;
  341.                         if (deadAndGone) then
  342.                             ExitAMortal;
  343.                         if (onward) then
  344.                             AdvanceALevel;
  345.                         repeat
  346.                             if GetNextEvent(everyEvent, myEvent) then
  347.                                 HandleGameEvent(myEvent);
  348.                         until (not pausing);
  349.                     end;
  350.             end;
  351.     until doneFlag;                       {End of the event loop}
  352.  
  353.     HUnlock(Handle(playRgn));
  354.     DisposeRgn(playRgn);
  355.     HUnlock(Handle(obeliskRgn1));
  356.     DisposeRgn(obeliskRgn1);
  357.     HUnlock(Handle(obeliskRgn2));
  358.     DisposeRgn(obeliskRgn2);
  359.     if (chanPtr <> nil) then
  360.         err := SndDisposeChannel(chanPtr, FALSE);
  361.     Close_MainWndo;
  362.  
  363.     ClosePort(offPlayerPort);
  364.     DisposPtr(Ptr(offPlayerPort));
  365.     ClosePort(offEnemyPort);
  366.     DisposPtr(Ptr(offEnemyPort));
  367.     ClosePort(offLoadPort);
  368.     DisposPtr(Ptr(offLoadPort));
  369.     ClosePort(offVirginPort);
  370.     DisposPtr(Ptr(offVirginPort));
  371.  
  372.     WriteOutScores;
  373.  
  374. end.                                    {End of the program}